package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tanhua.dubbo.mappers.UserMapper;
import com.tanhua.model.domain.User;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserApiImpl implements UserApi{
    @Autowired
    private UserMapper userMapper;
    @Override
    public User findByMobile(String mobile) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.eq(User::getMobile,mobile);
        User user = userMapper.selectOne(lqw);
        return user;
    }

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public User findById(Long userId) {
        return userMapper.selectById(userId);
    }

    //更新
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }

    //根据环信id查询
    @Override
    public User findByHuanxin(String huanxinId) {
        LambdaQueryWrapper<User> lqw = new LambdaQueryWrapper<>();
        lqw.eq(User::getHxUser,huanxinId);
        return userMapper.selectOne(lqw);
    }
}
